package com.xs.smc;

import com.xs.smc.entity.Order;
import com.xs.smc.enums.OrderEvent;
import com.xs.smc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication implements CommandLineRunner {

    @Autowired
    private OrderService orderService;

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        Order order = new Order(123L);
        System.out.println("初始状态: " + order.getStatus());

        orderService.processOrder(order, OrderEvent.CONFIRM);
        System.out.println("餐厅接单: " + order.getStatus());

        orderService.processOrder(order, OrderEvent.PREPARE);
        System.out.println("餐厅制作: " + order.getStatus());

        orderService.processOrder(order, OrderEvent.DELIVER);
        System.out.println("配送中: " + order.getStatus());

        orderService.processOrder(order, OrderEvent.COMPLETE);
        System.out.println("派送完成: " + order.getStatus());

        // 尝试非法流转
        boolean result = orderService.processOrder(order, OrderEvent.CANCEL);
        System.out.println("完成后取消订单，是否成功: " + result);
    }
}